package com.jinsp.cameralibrary.camera;

import android.graphics.Color;
import android.os.Environment;
import android.os.Parcel;
import android.os.Parcelable;

import java.io.File;

/**
 * Created by luoshuai on 1/5/22
 * <p>
 * 相机配置
 */
public class CameraConfigBean implements Parcelable {

    public static final String TAG = "CameraConfigBean";
    public static final int CAMERA_RATIO_16_9 = 0;
    public static final int CAMERA_RATIO_4_3 = 1;

    private boolean isShowTitleBar;
    private String titleText;
    private int titleBackgroundColor;
    private int titleTextColor;
    private int backDrawableId;
    private int takePhotoButtonDrawableId;
    private int switchCameraDrawableId;
    private int openFlashDrawableId;
    private int autoFlashDrawableId;
    private int closeFlashDrawableId;
    private int lightDrawableId;
    private String photoStoragePath;
    private int ratio;
    private int cameraPreviewBackgroundColor;
    private boolean isDefaultFront;

    public boolean isShowTitleBar() {
        return isShowTitleBar;
    }

    public String getTitleText() {
        return titleText;
    }

    public int getTitleBackgroundColor() {
        return titleBackgroundColor;
    }

    public int getTitleTextColor() {
        return titleTextColor;
    }

    public int getBackDrawableId() {
        return backDrawableId;
    }

    public int getTakePhotoButtonDrawableId() {
        return takePhotoButtonDrawableId;
    }

    public int getSwitchCameraDrawableId() {
        return switchCameraDrawableId;
    }

    public int getAutoFlashDrawableId() {
        return autoFlashDrawableId;
    }

    public int getCloseFlashDrawableId() {
        return closeFlashDrawableId;
    }

    public int getLightDrawableId() {
        return lightDrawableId;
    }

    public int getOpenFlashDrawableId() {
        return openFlashDrawableId;
    }

    public String getPhotoStoragePath() {
        return photoStoragePath;
    }

    public int getRatio() {
        return ratio;
    }

    public int getCameraPreviewBackgroundColor() {
        return cameraPreviewBackgroundColor;
    }

    public boolean isDefaultFront() {
        return isDefaultFront;
    }

    public static class Builder {

        private boolean isShowTitleBar;
        private String titleText = "Camera";
        private int titleBackgroundColor = Color.parseColor("#3F51B5");
        private int titleTextColor = Color.WHITE;
        private int backDrawableId;
        private int takePhotoButtonDrawableId;
        private int switchCameraDrawableId;
        private int openFlashDrawableId;
        private int autoFlashDrawableId;
        private int closeFlashDrawableId;
        private int lightDrawableId;
        private String photoStoragePath = Environment.getExternalStorageDirectory().getPath()
                + File.separator + "Camera";
        private int ratio = CAMERA_RATIO_16_9;
        private int cameraPreviewBackgroundColor = Color.BLACK;
        private boolean isDefaultFront;

        public Builder setShowTitleBar(boolean isShowTitleBar) {
            this.isShowTitleBar = isShowTitleBar;
            return this;
        }

        public Builder setTitleText(String titleText) {
            this.titleText = titleText;
            return this;
        }

        public Builder setTitleBackgroundColor(int titleBackgroundColor) {
            this.titleBackgroundColor = titleBackgroundColor;
            return this;
        }

        public Builder setTitleTextColor(int titleTextColor) {
            this.titleTextColor = titleTextColor;
            return this;
        }

        public Builder setBackDrawableId(int backDrawableId) {
            this.backDrawableId = backDrawableId;
            return this;
        }

        public Builder setTakePhotoButtonDrawableId(int takePhotoButtonDrawableId) {
            this.takePhotoButtonDrawableId = takePhotoButtonDrawableId;
            return this;
        }

        public Builder setSwitchCameraDrawableId(int switchCameraDrawableId) {
            this.switchCameraDrawableId = switchCameraDrawableId;
            return this;
        }

        public Builder setOpenFlashDrawableId(int openFlashDrawableId) {
            this.openFlashDrawableId = openFlashDrawableId;
            return this;
        }

        public Builder setAutoFlashDrawableId(int autoFlashDrawableId) {
            this.autoFlashDrawableId = autoFlashDrawableId;
            return this;
        }

        public Builder setCloseFlashDrawableId(int closeFlashDrawableId) {
            this.closeFlashDrawableId = closeFlashDrawableId;
            return this;
        }

        public Builder setLightDrawableId(int lightDrawableId) {
            this.lightDrawableId = lightDrawableId;
            return this;
        }

        public Builder setPhotoStoragePath(String photoStoragePath) {
            this.photoStoragePath = photoStoragePath;
            return this;
        }

        public Builder setCameraRatio(int cameraRatio) {
            this.ratio = cameraRatio;
            return this;
        }

        public Builder setCameraPreviewBackgroundColor(int cameraPreviewBackgroundColor) {
            this.cameraPreviewBackgroundColor = cameraPreviewBackgroundColor;
            return this;
        }

        public Builder setDefaultFront(boolean isDefaultFront) {
            this.isDefaultFront = isDefaultFront;
            return this;
        }

        public CameraConfigBean build() {
            CameraConfigBean cameraConfigBean = new CameraConfigBean();
            cameraConfigBean.isShowTitleBar = isShowTitleBar;
            cameraConfigBean.titleText = titleText;
            cameraConfigBean.titleBackgroundColor = titleBackgroundColor;
            cameraConfigBean.titleTextColor = titleTextColor;
            cameraConfigBean.backDrawableId = backDrawableId;
            cameraConfigBean.openFlashDrawableId = openFlashDrawableId;
            cameraConfigBean.autoFlashDrawableId = autoFlashDrawableId;
            cameraConfigBean.closeFlashDrawableId = closeFlashDrawableId;
            cameraConfigBean.lightDrawableId = lightDrawableId;
            cameraConfigBean.photoStoragePath = photoStoragePath;
            cameraConfigBean.ratio = ratio;
            cameraConfigBean.switchCameraDrawableId = switchCameraDrawableId;
            cameraConfigBean.takePhotoButtonDrawableId = takePhotoButtonDrawableId;
            cameraConfigBean.cameraPreviewBackgroundColor = cameraPreviewBackgroundColor;
            cameraConfigBean.isDefaultFront = isDefaultFront;
            return cameraConfigBean;
        }
    }

    @Override
    public String toString() {
        return "CameraConfigBean{" +
                "isShowTitleBar=" + isShowTitleBar +
                ", titleText='" + titleText + '\'' +
                ", titleBackgroundColor=" + titleBackgroundColor +
                ", titleTextColor=" + titleTextColor +
                ", backDrawableId=" + backDrawableId +
                ", takePhotoButtonDrawableId=" + takePhotoButtonDrawableId +
                ", switchCameraDrawableId=" + switchCameraDrawableId +
                ", openFlashDrawableId=" + openFlashDrawableId +
                ", autoFlashDrawableId=" + autoFlashDrawableId +
                ", closeFlashDrawableId=" + closeFlashDrawableId +
                ", lightDrawableId=" + lightDrawableId +
                ", photoStoragePath='" + photoStoragePath + '\'' +
                ", ratio=" + ratio +
                ", cameraPreviewBackgroundColor=" + cameraPreviewBackgroundColor +
                ", isDefaultFront=" + isDefaultFront +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte(this.isShowTitleBar ? (byte) 1 : (byte) 0);
        dest.writeString(this.titleText);
        dest.writeInt(this.titleBackgroundColor);
        dest.writeInt(this.titleTextColor);
        dest.writeInt(this.backDrawableId);
        dest.writeInt(this.takePhotoButtonDrawableId);
        dest.writeInt(this.switchCameraDrawableId);
        dest.writeInt(this.openFlashDrawableId);
        dest.writeInt(this.autoFlashDrawableId);
        dest.writeInt(this.closeFlashDrawableId);
        dest.writeInt(this.lightDrawableId);
        dest.writeString(this.photoStoragePath);
        dest.writeInt(this.ratio);
        dest.writeInt(this.cameraPreviewBackgroundColor);
        dest.writeByte(this.isDefaultFront ? (byte) 1 : (byte) 0);
    }

    public void readFromParcel(Parcel source) {
        this.isShowTitleBar = source.readByte() != 0;
        this.titleText = source.readString();
        this.titleBackgroundColor = source.readInt();
        this.titleTextColor = source.readInt();
        this.backDrawableId = source.readInt();
        this.takePhotoButtonDrawableId = source.readInt();
        this.switchCameraDrawableId = source.readInt();
        this.openFlashDrawableId = source.readInt();
        this.autoFlashDrawableId = source.readInt();
        this.closeFlashDrawableId = source.readInt();
        this.lightDrawableId = source.readInt();
        this.photoStoragePath = source.readString();
        this.ratio = source.readInt();
        this.cameraPreviewBackgroundColor = source.readInt();
        this.isDefaultFront = source.readByte() != 0;
    }

    private CameraConfigBean() {
    }

    protected CameraConfigBean(Parcel in) {
        this.isShowTitleBar = in.readByte() != 0;
        this.titleText = in.readString();
        this.titleBackgroundColor = in.readInt();
        this.titleTextColor = in.readInt();
        this.backDrawableId = in.readInt();
        this.takePhotoButtonDrawableId = in.readInt();
        this.switchCameraDrawableId = in.readInt();
        this.openFlashDrawableId = in.readInt();
        this.autoFlashDrawableId = in.readInt();
        this.closeFlashDrawableId = in.readInt();
        this.lightDrawableId = in.readInt();
        this.photoStoragePath = in.readString();
        this.ratio = in.readInt();
        this.cameraPreviewBackgroundColor = in.readInt();
        this.isDefaultFront = in.readByte() != 0;
    }

    public static final Parcelable.Creator<CameraConfigBean> CREATOR = new Parcelable.Creator<CameraConfigBean>() {
        @Override
        public CameraConfigBean createFromParcel(Parcel source) {
            return new CameraConfigBean(source);
        }

        @Override
        public CameraConfigBean[] newArray(int size) {
            return new CameraConfigBean[size];
        }
    };
}
